package com.kikcn.activemq;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.messaging.*;
import org.springframework.messaging.core.MessagePostProcessor;
import org.springframework.stereotype.Component;

import javax.jms.*;
import javax.jms.Message;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Component
public class Producer implements CommandLineRunner {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;


    @Override
    public void run(String... args) throws Exception {
        CCC cccc=new CCC();
        System.out.println(cccc.getA());

        Map<String,Object> header=new HashMap<>();
//        jmsMessagingTemplate.convertAndSend(queue,new MyMessage(null,"dddd"));
//
//        jmsMessagingTemplate.convertAndSend(queue,new MyMessage("b","bbbbbbb"));
    }

    public void send(MyMessage msg) {

        /*this.jmsMessagingTemplate.convertAndSend(this.queue, msg, new MessagePostProcessor() {
            @Override
            public org.springframework.messaging.Message<?> postProcessMessage(org.springframework.messaging.Message<?> message) {
               // message.getHeaders().put("name",msg.getName());
               return message;
            }
        });*/
    }

}

class MyMessage implements Serializable{
    public String name;
    public String message;

    public MyMessage(String name, String message) {
        this.name = name;
        this.message = message;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return this.message;
    }
}